package com.xulinhao.dao.impl;/**
 * @author xulinhao
 * @create 2021-06-02 15:35
 */

import com.xulinhao.dao.OrderDao;
import com.xulinhao.pojo.Order;

import java.util.List;

/**
 * @Author xlh
 * @packagename: com.xulinhao.dao.impl
 * @classname: OrderDaoImpl
 * @Description:
 * @Date 2021/6/2
 */
public class OrderDaoImpl extends BaseDao implements OrderDao {
    /**
     * 保存订单
     * @param order 订单
     * @return 影响的行数
     */
    @Override
    public int saveOrder(Order order) {
        String sql = "insert into t_order(`order_id`,`create_time`,`price`,`status`,`user_id`) values(?,?,?,?,?)";
        return update(sql,order.getOrderId(),order.getCreateTime(),order.getPrice(),order.getStatus(),order.getUserId());
    }

    /**
     * 查询全部订单
     * @return
     */
    @Override
    public List<Order> queryOrders() {
        String sql = "select `order_id` orderId , `create_time` createTime, `price` , `status` , `user_id` userId from t_order";
        return queryForList(Order.class, sql);
    }

    @Override
    public int changeOrderStatus(String orderId, Integer status) {
        String sql = "update t_order set `status`=? where `order_id`=? ";
        return update(sql,status,orderId);
    }

    @Override
    public List<Order> queryOrderByUserId(Integer userId) {
        String sql = "select `order_id` orderId, `create_time` createTime, `price` , `status` from t_order where `user_id`=?";
        return queryForList(Order.class, sql,userId);
    }
}
